﻿using DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ViewModels;

namespace BLL
{
    public class BookBLL
    {
        private BookDAL dal;//定义书籍数据访问类对象
        DataSet ds;
        public BookBLL()
        {
            dal = new BookDAL();//实例化数据访问类对象
            ds = new DataSet();
        }
        public DataSet GetBookList()
        {
            return dal.GetBookList();
        }
        public DataSet GetBookListByBookID(string inputString)
        {
            ds = dal.GetBookListByBookID(inputString);
            if (ds != null)
                return ds;
            else
                return null;
        }
        public DataSet GetBookListByBookName(string inputString)
        {
            return dal.GetBookListByBookName(inputString);
        }
        public DataSet GetBookListByPublisher(string inputString)
        {
            return dal.GetBookListByPublisher(inputString);
        }
        public DataSet GetBookListByAuthor(string inputString)
        {
            return dal.GetBookListByAuthor(inputString);
        }
        public DataSet GetBookClassList()
        {
            return dal.GetBookClassList();
        }
        public object EditBook(BookVM vm, string operation)
        {
            if (operation.Equals("Insert") && dal.BookDuplicateChecking(vm))
                return "库中已有该书籍记录，请勿重复插入！";
            else
                return dal.EditBook(vm, operation);
        }
        public DataSet GetBookByBookID(string bookid)
        {
            return dal.GetBookByBookID(bookid);
        }

        public bool DelBookByID(string bookid)
        {
            return dal.DelBookByID(bookid);
        }
        public object DelBookByBookID(string bookid)
        {
            bool result = dal.DelBookByID(bookid);
            if (result)
                return result;
            else if (!result)
                return result;
            else
            return "没有找到目标记录来完成删除操作！";
        }

    }
}
